package com.yesep.learn.mqtt.client.common.future;

import java.util.concurrent.atomic.AtomicBoolean;

import com.yesep.learn.mqtt.client.common.event.OneTimeEventCallBack;

import io.netty.handler.codec.mqtt.MqttConnAckMessage;
import io.netty.handler.codec.mqtt.MqttConnectReturnCode;

/**
 * 
 * @Description:
 */
public class ConnectFuture extends AbstractFuture<MqttConnAckMessage> implements Future<MqttConnAckMessage>, OneTimeEventCallBack<MqttConnAckMessage> {

	private final AtomicBoolean isConnect;

	public ConnectFuture(AtomicBoolean isConnect) {
		this.isConnect = isConnect;
	}

	@Override
	public void callback(MqttConnAckMessage msg) {
		isConnect.set(this.msg.variableHeader().connectReturnCode().equals(MqttConnectReturnCode.CONNECTION_ACCEPTED));
		setDone(msg);
	}
}
